﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.OleDb;

public partial class add_room : System.Web.UI.Page
{
    OleDbConnection conx;

    protected void Page_Load(object sender, EventArgs e)
    {

        if (DropDownList2.SelectedValue == "N")
        {
            DropDownList3.Enabled = false;
            //DropDownList3.SelectedValue = "";
        }
        else
            DropDownList3.Enabled = true;

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            String con = "Provider=MSDAORA;Data Source=orcl;Password=oracle;User ID=pearl";//"DSN=orcl;Driver={Microsoft ODBC for Oracle};UID=system;PWD=password;SERVER=localhost;";
            conx = new OleDbConnection(con);
            conx.Open();

            if (conx.State == ConnectionState.Open)
            {
                Label1.Text = "Oracle Connected";

                string tb1 = TextBox1.Text;
                string ddl1 = DropDownList1.SelectedValue;
                string ddl2 = DropDownList2.SelectedValue;
                string ddl3 = DropDownList3.SelectedValue;

                if (DropDownList2.SelectedValue == "N")
                    ddl3 = "";
                TextBox1.Text = "";


                OleDbCommand ODC = new OleDbCommand("INSERT INTO ROOMS VALUES ('" + tb1 + "','" + ddl1 + "','" + ddl2 + "','" + ddl3 + "')", conx);
                ODC.ExecuteNonQuery();
                OleDbCommand ODC_commit = new OleDbCommand("COMMIT", conx);
                ODC_commit.ExecuteNonQuery();
                Label1.Text = "\"New Room Inserted\"";
                
            }
            else
                Label1.Text = "Oracle Connect Failed";

        }

        catch (Exception ex)
        {
            Label1.Text = ex.Message + "<br />" + ex.StackTrace;
        }

        finally
        {
            conx.Close();
            conx = null;
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        Response.Redirect("room.aspx");
    }
    
}